package shuju;

class Queue {
    private LinkedList list;

    public Queue() {
        list = new LinkedList();
    }

    // 入队
    public void enqueue(int value) {
        list.add(value);
    }

    // 出队
    public int dequeue() {
        if (list.size() == 0) {
            throw new IllegalStateException("Queue is empty");
        }
        int value = list.get(0); // 获取队列头元素
        list.remove(0); // 删除队列头元素
        return value;
    }

    // 获取队列头元素
    public int peek() {
        if (list.size() == 0) {
            throw new IllegalStateException("Queue is empty");
        }
        return list.get(0);
    }

    // 队列是否为空
    public boolean isEmpty() {
        return list.size() == 0;
    }

    // 获取队列的大小
    public int size() {
        return list.size();
    }
}

